package com.blq.web.CustomerRepair.mapper;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.blq.web.CustomerRepair.domain.CustomerRepair;
import com.blq.web.CustomerRepair.domain.bo.CustomerRepairBo;
import com.blq.web.CustomerRepair.domain.vo.CustomerRepairVo;
import com.blq.common.core.mapper.BaseMapperPlus;
import com.blq.web.customerMode.entiy.TrendChartDto;
import org.apache.ibatis.annotations.Param;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 客户报修抢修Mapper接口
 *
 * @author Blq
 * @date 2022-08-31
 */
public interface CustomerRepairMapper extends BaseMapperPlus<CustomerRepairMapper, CustomerRepair, CustomerRepairVo> {

    List<CustomerRepairVo> selectCustomerRepairList(@Param(Constants.WRAPPER) CustomerRepairBo bo);

    Page<CustomerRepairVo> selectCustomerRepairList(@Param("page") Page<CustomerRepairVo> page, @Param("order") CustomerRepairBo bo);

    /**
     * 综合统计销售额
     * @param trendChart
     * @return
     */
    List<Map<String,Object>> selectSalesVolume(TrendChartDto trendChart);

    /**
     * 综合统计接单数
     * @param trendChart
     * @return
     */
    List<Map<String,Object>> selectReceiveNum(TrendChartDto trendChart);

    /**
     * 统合统计人员接单数及销售额
     * @param trendChart
     * @return
     */
    List<Map<String,Object>> selectUserOrderAndPrice(TrendChartDto trendChart);
    /**
     * 根据userId查询代办列表*
     * @param jsonObject
     * @return
     */
    List<CustomerRepair> selectPendingOrder(JSONObject jsonObject);

    /**
     * 根据userId和工单状态查询代办列表*
     * @param jsonObject
     * @return
     */
    List<CustomerRepair> selectByUserIdAndStatus(JSONObject jsonObject);

    /**
     * 根据userId和工单状态查询相关工单列表*
     * @param jsonObject
     * @return
     */
    List<CustomerRepair> viewAllUserOrders(JSONObject jsonObject);

    /**
     * 根据接单人和工单状态查询*
     * @param customerRepair
     * @return
     */
    List<CustomerRepair> selectByReceiverAndStatus(CustomerRepair customerRepair);

    /**
     * 综合查询工单*
     * @param customerRepair
     * @return
     */
    List<CustomerRepair> selectByCustomerRepair(@Param("page") Page<CustomerRepair> page, @Param("order") CustomerRepair customerRepair);

    Integer selectAnnouncementOfKh(@Param("id") String id);
    Integer selectAnnouncementOfSf(@Param("id") String id);
    Integer selectAnnouncementOfSh(@Param("id") String id);
    Integer selectAnnouncementOfCw(@Param("id") String id);

    Integer selectUserIsOrderKh(@Param("userId") String userId, @Param("orderId") String orderId);
    Integer selectUserIsOrderSf(@Param("userId") String userId, @Param("orderId") String orderId);
    Integer selectUserIsOrderSh(@Param("userId") String userId, @Param("orderId") String orderId);
    Integer selectUserIsOrderCw(@Param("userId") String userId, @Param("orderId") String orderId);

    /**
     * 查询登录账号各状态工单的数量*
     * @param userId 登录账号ID
     * @return
     */
    Map<String,Object> selectOrderStatusNum(@Param("userId") String userId, @Param("liaisonPhone") String liaisonPhone);

    /**
     * @Author: xiaw
     * 根据订单号查订单详情
     */
    JSONObject selectByCustomerKey(@Param("ticketRepair")  String ticketRepair);
    JSONObject selectByCustomerKey5(@Param("customerRepair")  String customerRepair);
    JSONObject selectByCustomerKeyw(@Param("ticketRepair")  String ticketRepair);
    /**
     * @Description 接口描述 :
     * @Params  * @param null
     * @Return 根据用户id查询所有的未读工单
     * @Author xiaw
     * @Date 2023/2/2 17:22
     */
    List<CustomerRepair> selectListByloginmanId(String loginmanId);
    /**
     * @Description 接口描述 :
     * @Params  * @param null
     * @Return 根据师傅id查未读订单
     * @Author xiaw
     * @Date 2023/2/2 17:48
     */
    List<CustomerRepair> selectListLikeCustomerPlayer(@Param("loginmanId") String loginmanId,@Param("aLong") Long aLong);



    /**
     * @Description 接口描述 :
     * @Params  * @param null
     * @Return 根据财务id查看它的待处理订单
     * @Author xiaw
     * @Date 2023/2/2 18:58
     */
    List<String> selectOrderIdListByFinanceId(String loginmanId);
    /**
     * @Description 接口描述 :
     * @Params  * @param null
     * @Return 根据审核人员id查询它的待处理订单号
     * @Author xiaw
     * @Date 2023/2/3 11:19
     */
    List<String> selectListByUserId(String loginmanId);
    /**
     * @Author: xiaw
     * 根据公司id查看 参看完成完成订单和 财务确认收款的订单
     *
     */
    List<CustomerRepair> selectListByCompany(@Param("aLong")String aLong,//公司id
                                             @Param("status") String status);//顶单状态


    /**
     * @Author: xiaw
     * 根据财务人员查看订单
     */

    List<CustomerRepair> selectListFinance( @Param("loginmanId") String loginmanId,
                                            @Param("type") String type ,
                                            @Param("company") String company);
    /**
     * @Author: xiaw
     * 审核员查看相关的所有订单
     */
    List<CustomerRepair> selectListByAudit(@Param("loginmanId") String loginmanId,
                                           @Param("type") String type ,
                                           @Param("company") String company);
    /**
     * @Author: xiaw
     * 根据施工人员查看所有订单--无状态查看所有订单
     */

    List<CustomerRepair> selectListByWorker(@Param("loginmanId")String loginmanId,
                                            @Param("type") String type,
                                            @Param("aLong") String company);


    void updateByKey( @Param("customerKey")String customerKey,
                      @Param("type2")String type2,
                      @Param("customerPlayer")String customerPlayer,
                      @Param("companyId")String companyId,
                      @Param("loginmanId")String loginmanId,
                      @Param("date") Date date
    );

    //根据订单号查订单详情
    CustomerRepair selectone(@Param("ticketRepair") String ticketRepair,
                            @Param("status") String status);
    //根据工单id修改工单
    void updateCustomerRepairBykey(CustomerRepair customerRepair);
    //分公司电站待处理订单
    List<CustomerRepair> selectListBypowerPlant( @Param("companyId")String companyId);

    /**
     * @Author: TTsing
     * 按指定年月查询已服务客户数
     */
    Integer selectNumberCustomersServedByMonth(@Param("date") String date);

    List<CustomerRepair> selectTimeoutOrder(@Param("minute") Integer minute);
    List<CustomerRepair> selectTimeoutOrderPool(@Param("minute") Integer minute);
    List<CustomerRepair> selectToPayoffOrder(@Param("hour") Integer hour, @Param("payoffState") Integer payoffState);
}
